import axios from "axios";

const host =
  // 利用环境判断自动切换地址：
  process.env.NODE_ENV === "development"
    ? // 本地地址
    "http://10.3.144.48:3000"
    : // 上线地址
    "http://120.76.247.5:2003";

const instance = axios.create({

});

instance.interceptors.request.use(
  function (config) {
    // 发出去之前的请求都会在这里
    let userinfo = localStorage.getItem("userinfo");
    try {
      userinfo = JSON.parse(userinfo) || {};
    } catch (err) {
      userinfo = {};
    }
    if (userinfo.authorization) {
      config.headers.authorization = userinfo.authorization;
    }
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

export default instance;
